package com.quectel.core.module.device.service.impl;


import com.quectel.core.module.device.dao.DeviceColumnMappingDao;
import com.quectel.core.module.device.dto.DeviceColumnMappingDto;
import com.quectel.core.module.device.entity.DeviceColumnMappingEntity;
import com.quectel.core.module.device.service.DeviceColumnMappingService;
import com.quectel.util.common.CopyUtils;
import com.quectel.util.kit.Snowflake;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author xianglianpeng
 * @date 2020-09-10 11:18:46
 */
@DubboService
public class DeviceColumnMappingServiceImpl implements DeviceColumnMappingService {

    private static final Logger LOGGER = LoggerFactory.getLogger(DeviceColumnMappingServiceImpl.class);

    @Autowired
    private DeviceColumnMappingDao deviceColumnMappingDao;


    @Override
    public List<DeviceColumnMappingDto> queryList(Map<String, Object> params) {
        List<DeviceColumnMappingEntity> list = deviceColumnMappingDao.queryList(params);
        return CopyUtils.copyList(list, DeviceColumnMappingDto.class);
    }

    @Override
    public int queryTotal(Map<String, Object> params) {
        return deviceColumnMappingDao.queryTotal(params);
    }

    @Override
    public Long save(DeviceColumnMappingDto dto) {
        DeviceColumnMappingEntity entity = CopyUtils.copyObj(dto, DeviceColumnMappingEntity.class);
        entity.setId(Snowflake.nextId());
        deviceColumnMappingDao.insert(entity);
        return entity.getId();
    }

    @Override
    public void updateById(DeviceColumnMappingDto dto) {
        DeviceColumnMappingEntity entity = CopyUtils.copyObj(dto, DeviceColumnMappingEntity.class);
        deviceColumnMappingDao.updateById(entity);
    }

    @Override
    public DeviceColumnMappingDto selectById(Long id) {
        DeviceColumnMappingEntity entity = deviceColumnMappingDao.selectById(id);
        return CopyUtils.copyObj(entity, DeviceColumnMappingDto.class);
    }

    @Override
    public void deleteById(Long id) {
        deviceColumnMappingDao.deleteById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteBatch(Long[] ids) {
        for (Long id : ids) {
            deleteById(id);
        }
    }
}
